package com.tjbank.cssys.web.service.impl;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkCreditOutWuReservedData;
import com.tjbank.cssys.repository.CkCreditOutWuReservedDataMapper;

import com.tjbank.cssys.web.service.CkCreditOutWuReservedDataService;

import com.tjbank.cssys.web.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CkCreditOutWuReservedDataServiceImpl implements CkCreditOutWuReservedDataService {
    private static Logger logger = LoggerFactory.getLogger(CkCreditOutWuReservedDataServiceImpl.class);

    @Autowired
    private CkCreditOutWuReservedDataMapper ckCreditOutWuReservedDataMapper;


    @Override
    public void updateAllotConfirm(Map<String, String> map) {
        logger.info("---确认预留案件start---param："+JSON.toJSONString(map));
        String batchNumber=map.get("batchNumber");
        String batchDate=batchNumber.substring(6,8);
        if(Integer.valueOf(batchDate)==15){
            map.put("batchDate","15");
        }else{
            map.put("batchDate","1");
        }
        ckCreditOutWuReservedDataMapper.updateAllotConfirm(map);
        logger.info("---确认预留案件start--succcess");
    }

    @Override
    public PageInfo getReservedData(Map<String, String> map) {
        logger.info("---查看预留案件start---param："+JSON.toJSONString(map));
        map.put("oneBatch",DateUtils.getlasetBatchNumber("01"));
        map.put("wuBatch",DateUtils.getlasetBatchNumber("15"));
        int page = Integer.parseInt(map.getOrDefault("page", "1").toString());
        int pageSize = Integer.parseInt(map.getOrDefault("pageSize", "10").toString());
        PageHelper.startPage(page, pageSize);
        List<Map<String,String>> list = ckCreditOutWuReservedDataMapper.getReservedData(map);
        PageInfo result = new PageInfo(list);
        logger.info("---查看预留案件end---result："+JSON.toJSONString(result));
        return result;
    }
}